package client.comm.baoding.ui

import android.content.Intent
import android.text.TextUtils
import androidx.lifecycle.Observer
import client.comm.baoding.R
import client.comm.baoding.api.bean.UserInfo
import client.comm.baoding.databinding.ActivityZzBinding
import client.comm.baoding.ui.vm.ZzViewModel
import client.comm.commlib.base.BaseActivity
import client.comm.commlib.dialog.ValidatePwdDialog
import client.comm.commlib.toast.toast
import client.comm.commlib.utils.StoreUtil


class ZzActivity : BaseActivity<ZzViewModel, ActivityZzBinding>() {

    override fun getLayout(): Int {
        return R.layout.activity_zz
    }

    override fun initView() {
        binding?.apply {
            event = this@ZzActivity
            vm = viewModel
            StoreUtil.getBean<UserInfo>(this@ZzActivity)?.let {
                viewModel.userInfo.value = it
                inconme = it.income.toString()
            }
        }
    }

    override fun observerUI() {
        viewModel.call.observe(this, Observer {
            it?.apply {
                if (isSuccess) {
                    toast("操作成功")
                    startActivity(Intent(this@ZzActivity, ZcJlActivity::class.java).apply {
                        putExtra("index", 1)
                    })
                    finish()
                } else {
                    toast(it.message)
                }
            }
        })
    }

    override fun initViewModel(): ZzViewModel = createViewModel()

    fun ok() {
        if (TextUtils.isEmpty(viewModel.txNum.value) || viewModel.username.value.isNullOrEmpty()) {
            toast("所有不能为空")
            return
        }
        ValidatePwdDialog(this).apply {
            title = "需要验证支付密码"
            ok = {
                viewModel.ok(it)
            }
        }.show()
    }

    fun jl() {
        startActivity(Intent(this@ZzActivity, ZcJlActivity::class.java).apply {
            putExtra("index", 1)
        })
    }
}